using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Net.Common.Tool
{
    public abstract class SerializeHelper
    {
        public static object DeserializeWithBinary(byte[] data)
        {
            MemoryStream serializationStream = new MemoryStream();
            serializationStream.Write(data, 0, data.Length);
            serializationStream.Position = 0L;
            object obj = new BinaryFormatter().Deserialize((Stream)serializationStream);
            serializationStream.Close();
            return obj;
        }

        public static byte[] SerializeToBinary(object obj)
        {
            MemoryStream serializationStream = new MemoryStream();
            new BinaryFormatter().Serialize((Stream)serializationStream, obj);
            byte[] array = serializationStream.ToArray();
            serializationStream.Close();
            return array;
        }
    }
}